<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('发布产品信息列表')" />
    <style>
        .img-circle {
            border-radius: 10%;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>[[#{productTitle}]]：</label>
                            <input type="text" name="productTitle"/>
                        </li>
                        <li>
                            <label>[[#{productAbbreviation}]]：</label>
                            <input type="text" name="productSimpleName"/>
                        </li>
                        <li>
                            <label>[[#{spu}]]：</label>
                            <input type="text" name="styleNo"/>
                        </li>
                        <li>
                            <label>[[#{status}]]：</label>
                            <select name="status" th:with="type=${@dict.getType('jt_product_status')}">
                                <option value="">[[#{all}]]</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>[[#{region}]]：</label>
                            <input type="text" name="publishCountryCode"/>
                        </li>
                        <li>
                            <label>[[#{salesTime}]]：</label>
                            <input type="text" class="time-input" id="beginOnSaleTime" th:placeholder="#{beginTime}" name="params[beginOnSaleTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endOnSaleTime" th:placeholder="#{endTime}" name="params[endOnSaleTime]" />
                        </li>
                        <li>
                            <label>[[#{createTime}]]：</label>
                            <input type="text" class="time-input" id="beginCreateTime" th:placeholder="#{beginTime}" name="params[beginCreateTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endCreateTime" th:placeholder="#{endTime}" name="params[endCreateTime]" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;[[#{search}]]</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;[[#{reset}]]</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addPopupRight()" shiro:hasPermission="business:pulish:add">
                <i class="fa fa-plus"></i> [[#{add}]]
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editPopupRight()" shiro:hasPermission="business:pulish:edit">
                <i class="fa fa-edit"></i> [[#{edit}]]
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:pulish:remove">
                <i class="fa fa-remove"></i> [[#{delete}]]
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:pulish:export">
                <i class="fa fa-download"></i> [[#{export}]]
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:pulish:edit')}]];
    var removeFlag = [[${@permission.hasPermi('business:pulish:remove')}]];
    var statusDatas = [[${@dict.getType('jt_product_status')}]];
    var prefix = ctx + "business/publish";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: i18n('commodityManagement'),
            columns: [{
                checkbox: true
            },
                {
                    field: 'productId',
                    title: '产品id',
                    visible: false
                },
                {
                    field: 'productTitle',
                    title: i18n('productTitle')
                },
                {
                    field: 'productSimpleName',
                    title: i18n('productAbbreviation')
                },
                {
                    field: 'imageUrl',
                    title: i18n("image"),
                    formatter: function(value, row, index) {
                        var imageUrl = value;
                        if(ctx.length > 1 && imageUrl != ""){
                            if(imageUrl.indexOf("/") == 0){
                                imageUrl = ctx + imageUrl.substr(1);
                            } else {
                                imageUrl = ctx + imageUrl;
                            }
                        }
                        return imageLazyLoadView(imageUrl, "auto", 750);
                    }
                },
                {
                    field: 'styleNo',
                    title: i18n('spu')
                },
                {
                    field: 'currency',
                    title: i18n('currency')
                },
                {
                    field: 'salePrice',
                    title: i18n("sellingPrice")
                },
                {
                    field: 'marketPrice',
                    title: i18n("marketPrice")
                },
                {
                    field: 'categoryNameZh',
                    title: i18n("product.category")
                },
                {
                    field: 'status',
                    title: i18n('status'),
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'publishRegion',
                    title: i18n('releaseRegion')
                },
                {
                    field: 'onSaleTime',
                    title: i18n('salesTime'),
                    sortable:true
                },
                {
                    field: 'createTime',
                    title: i18n('createTime'),
                    sortable:true
                },
                {
                    title: i18n('operate'),
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editPopupRight(\'' + row.productId + '\')"><i class="fa fa-edit"></i> '+i18n('edit')+'</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.productId + '\')"><i class="fa fa-remove"></i>'+i18n('edit')+'</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 图片预览
    function imageLazyLoadView(value, height, width, target) {
        if ($.common.isEmpty(width)) {
            width = 'auto';
        }
        if ($.common.isEmpty(height)) {
            height = 'auto';
        }
        if($.common.isMobile()){
            target = "blank";
        }
        var windowWidth = $(window).width();
        //console.log("imgW====="+windowWidth)
        var imgW = 'img-md';
        if(windowWidth < 1024){
            imgW = 'img-lg';
        }
        // blank or self
        var _target = $.common.isEmpty(target) ? 'self' : target;
        if ($.common.isNotEmpty(value)) {
            return $.common.sprintf("<img class='img-circle "+imgW+" lazyload' data-type='2' data-height='%s' data-width='%s' data-target='%s' src='%s' />", height, width, _target, value);
        } else {
            return $.common.nullToStr(value);
        }
    }
</script>
<script th:inline="javascript">
    var ROOT = [[${#servletContext.contextPath}]];
    var LANG_COUNTRY = [[${#locale.language+'_'+#locale.country}]];

    //初始化i18n
    $.i18n.properties({
        path: ROOT + '/i18n/',//这里表示访问路径
        name: 'messages',//文件名开头
        language: LANG_COUNTRY,//文件名语言 例如en_US
        mode: 'map'//默认值
    });

    //i18n函数
    function i18n(msgKey) {
        try {
            return $.i18n.prop(msgKey);
        } catch (e) {
            return msgKey;
        }
    }
</script>
</body>
</html>